{#**
 * 2007-2020 PrestaShop SA and Contributors
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * https://opensource.org/licenses/OSL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
 * versions in the future. If you wish to customize PrestaShop for your
 * needs please refer to https://www.prestashop.com for more information.
 *
 * @author    PrestaShop SA <contact@prestashop.com>
 * @copyright 2007-2020 PrestaShop SA and Contributors
 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
 * International Registered Trademark & Property of PrestaShop SA
 *#}

{% import '@PrestaShop/Admin/macros.html.twig' as ps %}

{% set messagesToShow = 4 %}

<div class="card mt-2 d-print-none">
  <div class="card-header">
    <div class="row">
      <div class="col-md-6">
        <h3 class="card-header-title">
          {{ 'Messages'|trans({}, 'Admin.Global') }} ({{ orderForViewing.messages.total }})
        </h3>
      </div>
      {% if orderForViewing.messages.total > messagesToShow %}
        <div class="col-md-6 text-right">
          <a
            href="#"
            data-toggle="modal"
            data-target="#view_all_messages_modal"
            class="d-print-none js-open-all-messages-btn"
          >
            {{ 'View full conversation'|trans({}, 'Admin.Orderscustomers.Feature') }}
          </a>
        </div>
      {% endif %}
    </div>
  </div>

  {% if orderForViewing.messages.messages is not empty %}
    <ul class="list-unstyled messages-block">
      {% for message in orderForViewing.messages.messages|slice(0, messagesToShow)|reverse %}
        {% include '@PrestaShop/Admin/Sell/Order/Order/Blocks/View/msg_list_item.html.twig' %}
      {% endfor %}
    </ul>
  {% endif %}

  <div class="card-body">
    {{ form_start(orderMessageForm, {
      'action': path('admin_orders_send_message', { orderId: orderForViewing.id })
    }) }}

    {{ ps.form_group_row(orderMessageForm.order_message, {}, {
      'label': 'Choose your order message'|trans({}, 'Admin.Orderscustomers.Feature'),
      'label_on_top': true,
      'class': 'mb-0'
    }) }}

    <div class="js-order-messages-container d-none">
      <div class="js-message-change-warning">{{ 'Do you want to overwrite your existing message?'|trans({}, 'Admin.Orderscustomers.Notification') }}</div>
      {% for id, message in orderMessageForm.vars['messages'] %}
        <div data-id="{{ id }}">
          {{ message }}
        </div>
      {% endfor %}
    </div>

    <div class="form-group row configure">
      <div class="col-sm">
        <a href="{{ path('admin_order_messages_index') }}" class="configure-link">
          {{ 'Configure predefined messages'|trans({}, 'Admin.Orderscustomers.Feature') }}
          <i class="material-icons">arrow_right_alt</i>
        </a>
      </div>
    </div>

    {{ ps.form_group_row(orderMessageForm.is_displayed_to_customer, {'material_design': true}) }}

    {{ ps.form_group_row(orderMessageForm.message, {'attr': { 'cols':30, 'rows':3 }}, {
      'label': 'Message'|trans({}, 'Admin.Global'),
      'label_on_top': true,
      'class': 'js-text-with-length-counter'
    }) }}

    {% block order_message_form_rest %}
      {{ form_rest(orderMessageForm) }}
    {% endblock %}

    <div class="text-right">
      <button type="submit" class="btn btn-primary">{{ 'Send message'|trans({}, 'Admin.Orderscustomers.Feature') }}</button>
    </div>

    {{ form_end(orderMessageForm) }}
  </div>
</div>

